package logic

import (
	"context"
	"gorm.io/gorm"
	"store/model/mysql"

	"store/storerpc/internal/svc"
	"store/storerpc/storerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *storerpc.AddRequest) (*storerpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	Add := mysql.Product{
		Model:       gorm.Model{},
		Product:     in.Product,
		Price:       in.Price,
		Store:       in.Store,
		Description: in.Description,
		UserID:      int(in.UserID),
	}
	mysql.DB.Debug().Model(&Add).Create(&Add)
	return &storerpc.AddResponse{Id: int64(Add.ID)}, nil
}
